<?php 
namespace app\admin\controller;

    use think\Controller;
    use think\Request;
    use think\Db;

class Order extends AdminBase
{
    
    /**
     * 显示已完成订单列表
     *
     * @return \think\Response
     */
    public function index(){
        // $list = Db::name('yshop as a,lamp_yshop_show as b')
        //        ->field('a.id,a.name,b.comment,b.icon,b.status,b.id as bid ')
        //        ->where('a.id = b.sid and a.hot = 2 and face = 1')
        //        ->group('a.id')->paginate(10);

        // $data = Db::name('lamp_zuser as z,lamp_order as o')
        //         ->field('o.`orderNum`,o.`tel`,o.`text`,o.`name`,z.`name`')
        //         ->where('o.uid = z.id and o.status = 1')
        //         ->select();

        $list = Db::name('zuser as z,lamp_order as o,lamp_yshop as y')
               ->field('o.id,o.orderNum,o.tel,o.text,o.name,z.id as zid,y.name as yname,y.tel as ytel')
               ->where('o.uid = z.id and o.status = 1 and y.id = o.sid')
               ->paginate(10);
        return view('admin@order/readyorder',[
            'list' => $list
        ]);
    }

    public function rorderdetail($id){
        $list = db::name('zuser as z,lamp_order as o,lamp_yshop as y')
               ->field('o.tel,o.text,o.name,z.id as zid,y.name as yname,y.tel as ytel')
               ->where('o.uid = z.id and y.id = o.sid and o.id ='.$id.'')
               ->select();
        return view('admin@order/rorderdetail',[
            'list' => $list
        ]);
    }

    public function rorderdel($id){
        db('order')->where('id',$id)->update(['status' => '4']);
        $this->success('删除成功');
    }


    /**
     * 显示未完成订单列表
     *
     * @return \think\Response
     */
    public function order(){
        $list = Db::name('zuser as z,lamp_order as o,lamp_yshop as y')
               ->field('o.id,o.orderNum,o.tel,o.text,o.name,z.id as zid,y.name as yname,y.tel as ytel')
               ->where('o.uid = z.id and o.status = 2 and y.id = o.sid')
               ->paginate();
        return view('admin@order/order',[
            'list' => $list
        ]);
    }

    public function orderdetail($id){

        $list = db::name('zuser as z,lamp_order as o,lamp_yshop as y')
               ->field('o.tel,o.text,o.name,z.id as zid,y.name as yname,y.tel as ytel')
               ->where('o.uid = z.id and y.id = o.sid and o.id ='.$id.'')
               ->select();
        return view('admin@order/orderdetail',[
            'list' => $list
        ]);
    }

    public function orderdel($id){

        $data = db('order')->where('id',$id)->update(['status' => '1']);

        if($data>0){
                $this->success('取消成功');
        }
    }
} 